<!DOCTYPE html>
<html lang="zh-CN" data-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能宠物小屋 - 远程控制</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/daisyui/4.12.10/full.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .glass-card {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        .status-indicator {
            animation: pulse 2s infinite;
        }
        @keyframes pulse {
            0% { opacity: 1; }
            50% { opacity: 0.5; }
            100% { opacity: 1; }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <!-- 顶部导航 -->
    <nav class="gradient-bg text-white shadow-lg">
        <div class="container mx-auto px-4 py-3">
            <div class="flex items-center justify-between">
                <div class="flex items-center space-x-3">
                    <i class="fas fa-home text-2xl"></i>
                    <h1 class="text-xl font-bold">智能宠物小屋</h1>
                </div>
                <div class="flex items-center space-x-4">
                    <div class="flex items-center space-x-2">
                        <div id="connectionStatus" class="w-3 h-3 bg-green-400 rounded-full status-indicator"></div>
                        <span class="text-sm">在线</span>
                    </div>
                    <button class="btn btn-ghost btn-sm">
                        <i class="fas fa-cog"></i>
                    </button>
                </div>
            </div>
        </div>
    </nav>

    <!-- 主要内容区域 -->
    <div class="container mx-auto px-4 py-6">
        <!-- 实时状态卡片 -->
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <div class="flex items-center justify-between">
                        <div>
                            <h3 class="text-sm text-gray-500">温度</h3>
                            <p class="text-2xl font-bold text-blue-600" id="temperature">24.5°C</p>
                        </div>
                        <div class="text-3xl text-blue-500">
                            <i class="fas fa-thermometer-half"></i>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <div class="flex items-center justify-between">
                        <div>
                            <h3 class="text-sm text-gray-500">湿度</h3>
                            <p class="text-2xl font-bold text-green-600" id="humidity">65%</p>
                        </div>
                        <div class="text-3xl text-green-500">
                            <i class="fas fa-tint"></i>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <div class="flex items-center justify-between">
                        <div>
                            <h3 class="text-sm text-gray-500">余粮</h3>
                            <p class="text-2xl font-bold text-orange-600" id="foodWeight">350g</p>
                        </div>
                        <div class="text-3xl text-orange-500">
                            <i class="fas fa-drumstick-bite"></i>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <div class="flex items-center justify-between">
                        <div>
                            <h3 class="text-sm text-gray-500">水位</h3>
                            <p class="text-2xl font-bold text-cyan-600" id="waterLevel">85%</p>
                        </div>
                        <div class="text-3xl text-cyan-500">
                            <i class="fas fa-glass-water"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 控制面板 -->
        <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
            <!-- 手动控制 -->
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <h2 class="card-title">
                        <i class="fas fa-sliders text-blue-500"></i>
                        手动控制
                    </h2>
                    
                    <div class="space-y-4">
                        <div class="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
                            <div>
                                <h4 class="font-medium">风扇控制</h4>
                                <p class="text-sm text-gray-500">自动温控已启用</p>
                            </div>
                            <input type="checkbox" class="toggle toggle-primary" id="fanToggle" checked>
                        </div>

                        <div class="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
                            <div>
                                <h4 class="font-medium">投食控制</h4>
                                <p class="text-sm text-gray-500">点击立即投食</p>
                            </div>
                            <button class="btn btn-primary btn-sm" onclick="feedPet()">
                                <i class="fas fa-utensils mr-2"></i>投食
                            </button>
                        </div>

                        <div class="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
                            <div>
                                <h4 class="font-medium">补水控制</h4>
                                <p class="text-sm text-gray-500">自动补水已启用</p>
                            </div>
                            <input type="checkbox" class="toggle toggle-primary" id="pumpToggle" checked>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 数据图表 -->
            <div class="card bg-base-100 shadow-xl">
                <div class="card-body">
                    <h2 class="card-title">
                        <i class="fas fa-chart-line text-green-500"></i>
                        24小时数据趋势
                    </h2>
                    <div id="chartContainer" class="h-64"></div>
                </div>
            </div>
        </div>

        <!-- 设备状态 -->
        <div class="card bg-base-100 shadow-xl mb-6">
            <div class="card-body">
                <h2 class="card-title">
                    <i class="fas fa-microchip text-purple-500"></i>
                    设备状态
                </h2>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                    <div class="text-center p-4 bg-green-50 rounded-lg">
                        <i class="fas fa-wifi text-2xl text-green-500 mb-2"></i>
                        <h4 class="font-medium">WiFi连接</h4>
                        <p class="text-sm text-green-600">已连接</p>
                    </div>
                    
                    <div class="text-center p-4 bg-blue-50 rounded-lg">
                        <i class="fas fa-memory text-2xl text-blue-500 mb-2"></i>
                        <h4 class="font-medium">STM32状态</h4>
                        <p class="text-sm text-blue-600">正常运行</p>
                    </div>
                    
                    <div class="text-center p-4 bg-orange-50 rounded-lg">
                        <i class="fas fa-battery-three-quarters text-2xl text-orange-500 mb-2"></i>
                        <h4 class="font-medium">电源状态</h4>
                        <p class="text-sm text-orange-600">正常供电</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- 通知中心 -->
        <div class="card bg-base-100 shadow-xl">
            <div class="card-body">
                <h2 class="card-title">
                    <i class="fas fa-bell text-red-500"></i>
                    通知中心
                </h2>
                
                <div class="space-y-3">
                    <div class="alert bg-yellow-50 border-l-4 border-yellow-400">
                        <div>
                            <i class="fas fa-exclamation-triangle text-yellow-500"></i>
                            <span class="ml-2">余粮不足，建议及时补充</span>
                        </div>
                    </div>
                    
                    <div class="alert bg-blue-50 border-l-4 border-blue-400">
                        <div>
                            <i class="fas fa-info-circle text-blue-500"></i>
                            <span class="ml-2">系统运行正常，所有传感器工作良好</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 底部导航 -->
    <div class="btm-nav btm-nav-md bg-base-100 border-t">
        <button class="active">
            <i class="fas fa-home"></i>
            <span class="btm-nav-label">首页</span>
        </button>
        <button>
            <i class="fas fa-chart-bar"></i>
            <span class="btm-nav-label">数据</span>
        </button>
        <button>
            <i class="fas fa-cog"></i>
            <span class="btm-nav-label">设置</span>
        </button>
    </div>

    <script>
        // 模拟实时数据更新
        function updateRealTimeData() {
            const temperature = (20 + Math.random() * 10).toFixed(1);
            const humidity = (50 + Math.random() * 30).toFixed(0);
            const foodWeight = Math.floor(300 + Math.random() * 100);
            const waterLevel = Math.floor(70 + Math.random() * 20);

            document.getElementById('temperature').textContent = temperature + '°C';
            document.getElementById('humidity').textContent = humidity + '%';
            document.getElementById('foodWeight').textContent = foodWeight + 'g';
            document.getElementById('waterLevel').textContent = waterLevel + '%';
        }

        // 初始化图表
        function initChart() {
            const chart = echarts.init(document.getElementById('chartContainer'));
            
            const option = {
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['温度', '湿度', '余粮', '水位'],
                    top: 0
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: ['00:00', '04:00', '08:00', '12:00', '16:00', '20:00', '24:00']
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    type: 'line',
                    data: [22, 23, 25, 27, 26, 24, 23],
                    name: '温度',
                    smooth: true,
                    lineStyle: { color: '#3B82F6' }
                }, {
                    type: 'line',
                    data: [60, 62, 65, 68, 66, 64, 62],
                    name: '湿度',
                    smooth: true,
                    lineStyle: { color: '#10B981' }
                }, {
                    type: 'line',
                    data: [400, 390, 380, 370, 360, 355, 350],
                    name: '余粮',
                    smooth: true,
                    lineStyle: { color: '#F59E0B' }
                }, {
                    type: 'line',
                    data: [90, 88, 85, 82, 80, 78, 75],
                    name: '水位',
                    smooth: true,
                    lineStyle: { color: '#06B6D4' }
                }]
            };
            
            chart.setOption(option);
            
            // 响应式调整
            window.addEventListener('resize', () => {
                chart.resize();
            });
        }

        // 投食功能
        function feedPet() {
            const button = event.target;
            button.disabled = true;
            button.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>投食中...';
            
            // 模拟投食过程
            setTimeout(() => {
                button.disabled = false;
                button.innerHTML = '<i class="fas fa-utensils mr-2"></i>投食';
                
                // 显示成功提示
                const toast = document.createElement('div');
                toast.className = 'toast toast-end';
                toast.innerHTML = `
                    <div class="alert bg-green-500 text-white">
                        <span>投食成功！</span>
                    </div>
                `;
                document.body.appendChild(toast);
                
                setTimeout(() => {
                    document.body.removeChild(toast);
                }, 3000);
            }, 2000);
        }

        // 控制开关事件
        document.getElementById('fanToggle').addEventListener('change', function(e) {
            console.log('风扇控制:', e.target.checked ? '开启' : '关闭');
        });

        document.getElementById('pumpToggle').addEventListener('change', function(e) {
            console.log('水泵控制:', e.target.checked ? '开启' : '关闭');
        });

        // 初始化
        document.addEventListener('DOMContentLoaded', function() {
            updateRealTimeData();
            initChart();
            
            // 每5秒更新一次数据
            setInterval(updateRealTimeData, 5000);
        });

        // 模拟WebSocket连接
        function simulateWebSocket() {
            // 这里可以添加实际的WebSocket连接代码
            console.log('连接到STM32设备...');
        }

        simulateWebSocket();
    </script>
</body>
</html>